package com.electronicmallapiidea;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.electronicmallapiidea.entity.User;
import com.electronicmallapiidea.mapper.UserMapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class Demo02_Wrapper {

    QueryWrapper<User> wrapper = Wrappers.query();
    QueryWrapper<User> wrapper2 = new QueryWrapper<>();
    @Autowired
    private UserMapper userMapper;

    @Test
    void test() {
//        wrapper.eq("username", "admin");      //获取username=admin的对象

//        wrapper.ne("username", "admin");      //获取username!=admin的对象

//        wrapper.gt("id", 1);        //获取id大于1的对象

//        wrapper.lt("id",3);     //获取id小于3的对象

//        wrapper.between("id",2,3);      //获取id在2~3之间的对象

//        wrapper.like("username","w");       //对username字段进行模糊查询

//        wrapper.orderByAsc("id");   //按升序排列

//        wrapper.orderByDesc("id");   //按降序排列

        wrapper.groupBy("username");
        wrapper.having("id",1);

        userMapper.selectList(wrapper).forEach(System.out::println);


    }


}
